
      <div class="mume markdown-preview   ">
        <h1 class="mume-header" id="go%E8%AF%AD%E8%A8%80%E5%BC%80%E5%8F%91%E7%8E%AF%E5%A2%83%E9%85%8D%E7%BD%AEvscode">Go语言开发环境配置(VSCode)</h1>
  
  <p>配置Go语言时遇到一些坑，特别是VSCode中Go工具<strong>包的安装</strong>及相关的<strong>科学上网</strong>知识，查了很多资料都描述不清晰，可能是我认为是难点的内容在别人那里是不需要说明的基础吧。</p>
  <p>其实只要科学上网配置完成，VSCode中安装工具包超级简单，对，是超级简单。好像本文标题不对？应该叫“Go语言工具包安装”？好吧，我在这里是把Go的环境变量等配置当作不需要说明的基础了，那些东东网上很多，我在本文略过了:)</p>
  <h4 class="mume-header" id="%E5%AE%89%E8%A3%85go">安装go</h4>
  
  <p>略</p>
  <h4 class="mume-header" id="%E5%AE%89%E8%A3%85git">安装git</h4>
  
  <p>略</p>
  <h4 class="mume-header" id="vs-code%E9%85%8D%E7%BD%AE">VS Code配置</h4>
  
  <ul>
  <li>
  <p>1.安装go扩展<br>
  在vscode扩展中搜“go”,选择microsoft官方的ms-vscode.go</p>
  </li>
  <li>
  <p>2.安装相关工具包</p>
  <ul>
  <li>通过VSCode安装<br>
  操作很简单，但需要科学上网（见下面第4条）
  <ul>
  <li>
  <p>1)Ctrl + Shift + P</p>
  </li>
  <li>
  <p>2)输入<code>Go: install/update tools</code></p>
  </li>
  <li>
  <p>3)All Select,确定</p>
  </li>
  <li>
  <p>4)部分工具需要科学上网。注意为VSCode设置[用户设置]http代理:<br>
  此处以SSR为例，请先安装并完成SSR客户端配置</p>
  <ul>
  <li>4.1) windows下先启动SSR客户端，再对VSCode设置：</li>
  </ul>
  <pre data-role="codeBlock" data-info="json" class="language-json"><span class="token property">"http.proxy"</span><span class="token operator">:</span> <span class="token string">"127.0.0.1:1080"</span><span class="token punctuation">,</span>  
  </pre><ul>
  <li>4.2) linux下需要<a href="https://www.cnblogs.com/liuxuzzz/p/5324749.html">使用privoxy</a>一类的工具，安装配置好privoxy之后，再设置VSCode</li>
  </ul>
  <pre data-role="codeBlock" data-info="json" class="language-json"><span class="token property">"http.proxy"</span><span class="token operator">:</span> <span class="token string">"http://localhost:8118/"</span><span class="token punctuation">,</span>  
  </pre><pre data-role="codeBlock" data-info="javascript" class="language-javascript"><span class="token keyword">if</span> <span class="token punctuation">(</span>a <span class="token operator">==</span> b<span class="token punctuation">)</span> <span class="token punctuation">{</span>
         <span class="token keyword">var</span> c <span class="token operator">=</span> <span class="token string">"21"</span><span class="token punctuation">;</span>
      <span class="token punctuation">}</span>
  </pre><pre data-role="codeBlock" data-info="go" class="language-go"><span class="token keyword">if</span> a <span class="token operator">==</span> b <span class="token punctuation">{</span>
         <span class="token keyword">var</span> c <span class="token operator">=</span> <span class="token string">"21"</span><span class="token punctuation">;</span>
      <span class="token punctuation">}</span>
  </pre><p>注：因为要跑本地服务，因此需要去掉Privoxy/config中<code># forward localhost/ .</code>注释</p>
  <pre data-role="codeBlock" data-info="shell" class="language-shell">forward           localhost/     <span class="token keyword">.</span>  
  </pre></li>
  </ul>
  </li>
  <li>手动安装
  <ul>
  <li>使用go get，例如：<pre data-role="codeBlock" data-info="shell" class="language-shell">go get -u github.com/gin-gonic/gin  
  </pre>部分包需要科学上网，可参考前面科学上网说明</li>
  <li>不想翻墙的安装方法<pre data-role="codeBlock" data-info="shell" class="language-shell"><span class="token comment"># 注意，github下golang/镜像中的包需要放到golang.org/x目录下  </span>
  <span class="token function">git</span> clone https://github.com/golang/net.git <span class="token variable">$GOPATH</span>/src/golang.org/x/net  
  <span class="token function">git</span> clone https://github.com/golang/sys.git <span class="token variable">$GOPATH</span>/src/golang.org/x/sys  
  <span class="token function">git</span> clone https://github.com/golang/tools.git <span class="token variable">$GOPATH</span>/src/golang.org/x/tools  
  </pre></li>
  </ul>
  </li>
  </ul>
  </li>
  <li>
  <p>3.配置</p>
  <ul>
  <li>设置toolsGopath(原因参考<a href="https://blog.csdn.net/ys5773477/article/details/78881841">vscode golang详细配置</a>中的【<strong>注：坑点</strong>】)<br>
  在VSCode[用户设置]中添加：<pre data-role="codeBlock" data-info="json" class="language-json"><span class="token property">"go.toolsGopath"</span><span class="token operator">:</span> <span class="token string">"F:\\SourceCode\\go"</span><span class="token punctuation">,</span>  
  </pre></li>
  <li>debug配置<br>
  使用默认配置<br>
  debug配置的更多信息，参考官方Wiki： <a href="https://github.com/Microsoft/vscode-go/wiki/Debugging-Go-code-using-VS-Code">Debugging Go code using VS Code</a></li>
  </ul>
  </li>
  </ul>
</div>